﻿'******************************* File Header *********************************
'* File Name:    WmiTransactionTest.vb
'* Project:      WmiConnection.Test
'* Copyright (c) Freddy Kuehne
'*
'* Unit tests for WmiTransaction.
'* 
'* This source is subject to the GNU Library General Public License (LGPL).
'* See http://wmiconnection.codeplex.com/license.
'* All other rights reserved.
'*****************************************************************************
Imports System.Text
Imports System.Data.Common

<TestClass()>
Public Class WmiTransactionTest
#Region "Tests"
  <TestMethod()>
  Public Sub ConstructorTest()
    Using con As New WmiConnection()
      con.Open()
      Using target = con.BeginTransaction
        Assert.IsNotNull(target)
        Assert.IsInstanceOfType(target, GetType(WmiTransaction))
      End Using
    End Using
  End Sub

  <TestMethod()>
  Public Sub HierarchyTest()
    Using con As New WmiConnection
      con.Open()
      Using target = con.BeginTransaction
        Assert.IsInstanceOfType(target, GetType(DbTransaction))
      End Using
    End Using
  End Sub

  <TestMethod()>
  Public Sub IsolationLevelTest()
    Using con As New WmiConnection()
      con.Open()
      Using target = con.BeginTransaction()
        Assert.AreEqual(IsolationLevel.Unspecified, target.IsolationLevel)
      End Using

      ' no isolationlevel used!
      Using target = con.BeginTransaction(IsolationLevel.Serializable)
        Assert.AreEqual(IsolationLevel.Unspecified, target.IsolationLevel)
      End Using
    End Using
  End Sub

  <TestMethod()>
  Public Sub CommitTest()
    Using con As New WmiConnection()
      con.Open()
      Using target = con.BeginTransaction()
        ' no exception
        target.Commit()
      End Using

      Using target = con.BeginTransaction()
        ' no exception
        target.Rollback()
        target.Commit()
      End Using
    End Using
  End Sub

  <TestMethod()>
  Public Sub RollbackTest()
    Using con As New WmiConnection()
      con.Open()
      Using target = con.BeginTransaction()
        ' no exception
        target.Rollback()
      End Using

      Using target = con.BeginTransaction()
        ' no exception
        target.Commit()
        target.Rollback()
      End Using
    End Using
  End Sub

  <TestMethod()>
  Public Sub ConnectionTest()
    Using con As New WmiConnection()
      con.Open()
      Using target = con.BeginTransaction()
        Assert.AreSame(con, target.Connection)
      End Using
    End Using
  End Sub
#End Region
End Class
